<template>
    <div>
        <div class="search-con search-con-top">
            用户信息：
            <Input v-model="searchData.user_name" style="width: 150px" placeholder="昵称、手机号"></Input>
            提现状态：
            <Select style="width:100px" v-model="searchData.status">
                <Option value="">请选择</Option>
                <Option value="0">待审核</Option>
                <Option value="1">审核通过</Option>
                <Option value="2">已拒绝</Option>
            </Select>
            申请时间：
            <DatePicker type="datetime" v-model="searchData.start_time" placeholder="开始时间" style="width: 180px">
            </DatePicker>
            <span style="margin: 0 3px;">-</span>
            <DatePicker type="datetime" v-model="searchData.end_time" placeholder="结束时间" style="width: 180px"></DatePicker>
            <Button @click="search" type="primary" icon="ios-search" style="margin-left: 10px;">搜索</Button>
            <Button @click="reset" type="success" icon="ios-refresh" style="margin-left: 10px;">刷新</Button>
        </div>
        <br>
        <Table :columns="columns" :data="list" @on-sort-change="customSort" :highlight-row="true" max-height="800" border
            stripe>
            <template slot-scope="{ row , index}" slot="typeSlot">
                <div @click="showPaymentInfoDao(row)">
                    <img :src="baseImgeUrl + row.frontal_photo" style="width: 60px;height: 60px;">

                    <img :src="baseImgeUrl + row.backside_photo" style="width: 60px;height: 60px;"/>
                </div>
            </template>

            <template slot-scope="{ row , index}" slot="statusSlot">
                <span v-if="row.status == 0">待审核</span>
                <span v-if="row.status == 1" style="color: blue;">已通过</span>
                <span v-if="row.status == 2" style="color: red;">已拒绝</span><br />
                <span v-if="row.status == 2" style="color: red;">{{ row.reason }}</span>
            </template>
            <template slot-scope="{ row , index}" slot="makeSlot">
                <Button type="primary" size="small" @click="pass(row.id)" v-show="row.status == 0">通过</Button>
                <Button type="error" style="margin-left: 10px;" size="small" @click="showModal(row.id)"
                    v-show="row.status == 0">拒绝</Button>
            </template>
        </Table>
        <Paginate :total="total" @on-change="changePage" @on-page-size-change="changeSize"></Paginate>
        <Modal v-model="showAdd" title="实名认证审核" @on-ok="audit">
            请输入拒绝理由：
            <Input v-model="reason" type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="请输入..."></Input>

        </Modal>

        <Modal v-model="showPaymentInfo" title="收款信息">
            <img :src="baseImgeUrl + paymentInfo.frontal_photo" style="width: 100%;height: 100%;"/>

            <img :src="baseImgeUrl + paymentInfo.backside_photo" style="width: 100%;height: 100%;"/>
        </Modal>
    </div>
</template>

<script>
import config from "@/config";
import Paginate from "@/components/paginate/paginate.vue";
const baseImgeUrl = process.env.NODE_ENV === "development" ? config.baseUrl.dev : config.baseUrl.pro;
export default {
    name: "withdrawList",
    components: {
        Paginate,
    },
    data() {
        return {
            baseImgeUrl: baseImgeUrl,
            // 列表
            columns: [
                {
                    title: '用户名称',
                    align: "center",
                    key: 'user_name',
                    sortable: 'custom',
                },
                {
                    title: '用户手机号',
                    align: "center",
                    key: 'mobile',
                    width: 120,
                    sortable: 'custom',
                },
                {
                    title: '姓名',
                    align: "center",
                    key: 'name',
                    sortable: 'custom',
                },
                {
                    title: '手机号',
                    align: "center",
                    key: 'phone',
                    width: 120,
                    sortable: 'custom',
                },

                {
                    title: '证件类型',
                    align: "center",
                    key: 'document_type',
                    sortable: 'custom',
                },
                {
                    title: '证件号码',
                    align: "center",
                    key: 'id_card',
                    sortable: 'custom',
                },
                {
                    title: '证件图片',
                    align: "center",
                    slot: 'typeSlot',
                    //key: 'type',
                    sortable: 'custom',
                },
                {
                    title: '状态',
                    align: "center",
                    slot: 'statusSlot',
                    key: 'status',
                    sortable: 'custom',
                },
                {
                    title: '提交时间',
                    align: "center",
                    key: 'create_time',
                    sortable: 'custom',
                },
                {
                    title: '审核时间',
                    align: "center",
                    key: 'audit_time',
                    sortable: 'custom',
                },
                {
                    title: '操作',
                    align: "center",
                    width: "130",
                    slot: 'makeSlot',
                },
            ],
            // 数据
            list: [],
            total: 0,
            searchData: {
                page: 1,
                limit: 10,
            },
            showAdd: false,
            reason: '',
            id: 0,
            showPaymentInfo: false,
            paymentInfo: {},
        }
    },
    methods: {
        getList() {
            const param = {
                ...this.searchData
            };
            this.$axios('/admin/user/getAuthenticationList', param).then(res => {
                this.list = res.data;
                this.total = res.total;
            });
        },
        search() {
            this.searchData.page = 1;
            this.getList();
        },
        reset() {
            this.searchData = {
                page: 1,
                limit: 10,
            };
            this.getList();
        },
        changePage(page) {
            this.searchData.page = page;
            this.getList();
        },
        changeSize(size) {
            this.searchData.limit = size;
            this.getList();
        },
        customSort(column, key, order) {
            this.searchData.order_by = column.key;
            this.searchData.sort = column.order;
            this.getList();
        },
        // 显示添加角色弹窗
        showModal(id, type) {
            this.showAdd = true;
            this.id = id
        },
        audit() {
            this.$axios('/admin/user/authenticationAudit', { id: this.id, status: 2, reason: this.reason }).then(res => {
                this.$Message.success('审核成功');
                this.getList();
            })
        },
        // 添加角色
        pass(id) {
            this.$axios('/admin/user/authenticationAudit', { id: id, status: 1 }).then(res => {
                this.$Message.success('审核成功');
                this.getList();
            })
        },
        //
        showPaymentInfoDao(row) {
            this.showPaymentInfo = true;
            this.paymentInfo = row;
        },
    },
    created() {
        // 查询自己管理员
        this.getList();
    }
}
</script>

<style>
.inputMaxWidth {
    max-width: 180px;
    margin-left: 10px;
}
</style>
